# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.


from crypt_print.crypt_url import url_encrypt
from crypt_print.crypt_rsa import rsa_encrypt
from crypt_print.crypt_aes import aes_encrypt


# 用这一个就可以了
from crypt_print.crypt_nuonuo import print_encrypt


def test_print_encrypt():
    tin = '91370700165446588H'
    rsa_pub_key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQClj0t1b+O5Cq06d0yp4qZHM3OhNSmoaArC6qAhehT/DB23F/CCUSFrQCjADhOvCq+xu4JcNGQ1kpjhKVNb642QPlSDJ04QM/+3mKcu/WKLDZ+3zQYvNY41pcjTyxtUT9ixaBx8OQQfOp+qiAYYBtE9T6WRLCrl1YN0drpDvFylyQIDAQAB"
    aes_key = 'OrUPI3VOgAvLtyxA'
    # print_type 0---发票打印，1---清单打印，2---批量打印，3-清单批量打印
    print_type = '0'

    fp_code = '037002200105'
    fp_num = '05548060'
    fp_amount = 54197.70

    res = print_encrypt(tin, rsa_pub_key, aes_key,
                        print_type, fp_code, fp_num, fp_amount)
    print('print ok', res)


def test_all():
    tin = '91370700165446588H'
    rsa_pub_key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQClj0t1b+O5Cq06d0yp4qZHM3OhNSmoaArC6qAhehT/DB23F/CCUSFrQCjADhOvCq+xu4JcNGQ1kpjhKVNb642QPlSDJ04QM/+3mKcu/WKLDZ+3zQYvNY41pcjTyxtUT9ixaBx8OQQfOp+qiAYYBtE9T6WRLCrl1YN0drpDvFylyQIDAQAB"

    aes_key = 'OrUPI3VOgAvLtyxA'
    print('aes_key', aes_key)

    # print_type 0---发票打印，1---清单打印，2---批量打印，3-清单批量打印
    print_type = '0'

    fp_code = '037002200105'
    fp_num = '05548060'
    fp_amount = 54197.70

    print('message',  print_type, fp_code, fp_num, fp_amount)

    aes_ok = aes_encrypt(aes_key, print_type, fp_code, fp_num, fp_amount)
    print('aes_ok', aes_ok, len(aes_ok))

    rsa_ok = rsa_encrypt(rsa_pub_key, aes_ok)
    print('rsa_ok', rsa_ok)

    url_ok = url_encrypt(tin, rsa_ok)

    print('url_ok', url_ok)


def test_url():

    tin = '91370700165446588H'
    message = 'BVyVHB/8Z87X9SPGvVs3nrt0OpxadAs1hTKksSk3QNyL2t6kSu93HvYeiFbkRsDPForSNRGfq5HFgf+FR77TcAnipE4ZQL4pMPTQ4/oaBXsITKIrKTYVpbOmO8yLZJiVh42Hx2XkiwsS7psB5fM1L9eX5f2ZyH3yEmF6V6VsEJg='
    print('message', message)
    res = url_encrypt(tin, message)

    print('url_ok', res)


def test_rsa():
    PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQClj0t1b+O5Cq06d0yp4qZHM3OhNSmoaArC6qAhehT/DB23F/CCUSFrQCjADhOvCq+xu4JcNGQ1kpjhKVNb642QPlSDJ04QM/+3mKcu/WKLDZ+3zQYvNY41pcjTyxtUT9ixaBx8OQQfOp+qiAYYBtE9T6WRLCrl1YN0drpDvFylyQIDAQAB"
    message = '6270B399EE3AD467DDEEEC43EE6AFE156A44FCA594A1C849480F0A1B0FAFEB16'
    message = '6270B399EE3AD467DDEEEC43EE6AFE15979F17041C78936E951AE0E1D189729B08A47305D1DD7B1CD4E08913C582C943'
    print('PUBLIC_KEY', PUBLIC_KEY)
    print('message', message)
    rsa_ok = rsa_encrypt(PUBLIC_KEY, message)
    print('rsa_ok', rsa_ok)


def test_aes():

    key = 'OrUPI3VOgAvLtyxA'
    print('key', key)

    # message = '0!037002200105!05548062!5600.00'
    # # res = 6270B399EE3AD467DDEEEC43EE6AFE156A44FCA594A1C849480F0A1B0FAFEB16

    # message = '0!037002200105!05548060!54197.70'
    # # res = 6270B399EE3AD467DDEEEC43EE6AFE15979F17041C78936E951AE0E1D189729B08A47305D1DD7B1CD4E08913C582C943
    # #       6270B399EE3AD467DDEEEC43EE6AFE15979F17041C78936E951AE0E1D189729B08A47305D1DD7B1CD4E08913C582C943
    #         6270B399EE3AD467DDEEEC43EE6AFE15979F17041C78936E951AE0E1D189729B08A47305D1DD7B1CD4E08913C582C943
    #         6270B399EE3AD467DDEEEC43EE6AFE15979F17041C78936E951AE0E1D189729B08A47305D1DD7B1CD4E08913C582C943
    # message = '0!037002200105!05548060!923872342342342454646656465654765.21'

    # print_type 0---发票打印，1---清单打印，2---批量打印，3-清单批量打印
    print_type = '0'

    code = '037002200105'
    num = '05548060'
    amount = 54197.70

    print('message',  print_type, code, num, amount)

    aes_enc = aes_encrypt(key, print_type, code, num, amount)
    # aes_enc = aes_ecb_encrypt(message, key)
    # 6270B399EE3AD467DDEEEC43EE6AFE156A44FCA594A1C849480F0A1B0FAFEB16
    print('aes_ok', aes_enc, len(aes_enc))


if __name__ == '__main__':

    # test_aes()
    # test_rsa()
    # test_url()

    # test_all()
    test_print_encrypt()
